package com.tqw.shipping.service.imp;

import com.tqw.shipping.mapper.AreaMapper;
import com.tqw.shipping.pojo.Area;
import com.tqw.shipping.service.AreaService;
import com.tqw.vo.AreaVO;
import com.tqw.vo.ShippingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: czm
 * @Date: 2022/04/07/14:04
 * @Description:
 */
@Service
public class AreaServiceImp implements AreaService {
    @Autowired
    private AreaMapper areaMapper;

    @Override
    public List<Area> getAllArea() {
        return areaMapper.selectList();
    }

    @Override
    public AreaVO getAreaInfo(Integer streetId) {
        Area streetInfo = areaMapper.selectById(streetId);
        Area regionInfo = areaMapper.selectById(streetInfo.getParentId());
        Area cityInfo = areaMapper.selectById(regionInfo.getParentId());
        Area provinceInfo = areaMapper.selectById(cityInfo.getParentId());
        AreaVO areaVO = new AreaVO();
        areaVO.setProvinceId(provinceInfo.getId()).setProvinceName(provinceInfo.getName())
                .setCityId(cityInfo.getId()).setCityName(cityInfo.getName())
                .setRegionId(regionInfo.getId()).setRegionName(regionInfo.getName())
                .setStreetId(streetInfo.getId()).setStreetName(streetInfo.getName());
        return areaVO;
    }

}
